package cn.itcast.Service;

import cn.itcast.dao.EmployeeDao;
import cn.itcast.domain.Employee;
import cn.itcast.domain.EmployeeExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeService {
    @Autowired
    EmployeeDao employeeDao;

    public List<Employee> getAll() {
        return  employeeDao.selectByExampleWithDept(null);
    }

    public void save(Employee employee){
        employeeDao.insertSelective(employee);
    }

    public boolean checkUser(String empName) {
        EmployeeExample example = new EmployeeExample();
        EmployeeExample.Criteria criteria = example.createCriteria();
        criteria.andEmpNameEqualTo(empName);

        long l = employeeDao.countByExample(example);
      return l ==0;

    }

    public Employee getEmp(Integer id) {
        Employee employee = employeeDao.selectByPrimaryKey(id);
        return employee;
    }

    public void updateEmp(Employee employee) {
        employeeDao.updateByPrimaryKeySelective(employee);
    }

    public void deleteEmp(Integer id) {
        employeeDao.deleteByPrimaryKey(id);
    }

    public void deleteBatch(List<Integer> id_list) {
        EmployeeExample example = new EmployeeExample();
        EmployeeExample.Criteria criteria = example.createCriteria();
        criteria.andEmpIdIn(id_list);

        employeeDao.deleteByExample(example);
    }
}
